// https://iai.sh.cn/problem/96
#include <bits/stdc++.h>
using namespace std;
int a[100001];
int f[100001][3];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  f[1][0] = a[1];
  f[1][1] = 2 * a[1];
  f[1][2] = 0;
  for (int i = 2; i <= n; i++) {
    f[i][0] = max(f[i - 1][0], f[i - 1][2]) + a[i];
    f[i][1] = max(f[i - 1][0], f[i - 1][2]) + 2 * a[i];
    f[i][2] = f[i - 1][1];
  }
  cout << max(max(f[n][0], f[n][1]), f[n][2]);

  return 0;
}